import { createI18n } from 'vue-i18n'
import sysConfig from "@/config"

import zhCN from 'ant-design-vue/es/locale/zh_CN'
import enUS from 'ant-design-vue/es/locale/en_US'

import zh_cn from './lang/zh-CN'
import en_us from './lang/en-US'
import lwd from './lang/lwd'

const messages = {
	'zh-cn': Object.assign(zh_cn, zhCN),
	'en-us': Object.assign(en_us, enUS),
	'lwd': lwd,
}
const getData = (key) => {
	try {
		const value = JSON.parse(localStorage.getItem(key))
		if (value) {
			let nowTime = new Date().getTime()
			if (nowTime > value.datetime && value.datetime !== 0) {
				localStorage.removeItem(key)
				return null;
			}
			return value.content
		}
		return null
	} catch (err) {
		return null
	}
}
// console.log(messages['en_us'])
// console.log(enUS)
const i18n = createI18n({
	locale: getData("APP_LANG") || sysConfig.LANG,
	fallbackLocale: 'zh-cn',
	globalInjection: true,
	messages,
})

export default i18n;
